﻿namespace LinFu.AOP.Interfaces
{
    using System;

    public class SimpleMethodReplacementProvider : BaseMethodReplacementProvider
    {
        #region Constructors

        public SimpleMethodReplacementProvider(IMethodReplacement replacement)
        {
            MethodReplacement = replacement;
        }

        #endregion Constructors

        #region Properties

        public IMethodReplacement MethodReplacement
        {
            get;
            set;
        }

        public Predicate<IInvocationContext> MethodReplacementPredicate
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        public override bool ShouldReplace(IInvocationContext context)
        {
            if (MethodReplacementPredicate == null)
                return true;

            return MethodReplacementPredicate(context);
        }

        protected override IMethodReplacement GetReplacement(IInvocationContext context)
        {
            return MethodReplacement;
        }

        #endregion Methods
    }
}